package com.oamicnet.serviceone.server.service.impl;

import com.oamicnet.serviceone.api.teacher.vo.TeacherVO;
import com.oamicnet.serviceone.server.converter.TeacherConverter;
import com.oamicnet.serviceone.server.entity.Teacher;
import com.oamicnet.serviceone.server.mapper.TeacherMapper;
import com.oamicnet.serviceone.server.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Autowired
    private TeacherConverter teacherConverter;

    @Override
    public List<TeacherVO> findAll() {
        return teacherConverter.convertToTeacherVOList(teacherMapper.selectList(null));
    }

    @Override
    public void save(TeacherVO teacherVO) {
        Teacher teacher = teacherConverter.convertToTeacher(teacherVO);
        teacherMapper.insert(teacher);
    }

    @Override
    public void update(TeacherVO teacherVO) {
        Teacher teacher = teacherConverter.convertToTeacher(teacherVO);
        teacherMapper.updateById(teacher);
    }

    @Override
    public TeacherVO get(Long id) {
        return teacherConverter.convertToTeacherVO(teacherMapper.selectById(id));
    }

    @Override
    public void delete(Long id) {
        teacherMapper.deleteById(id);
    }
}
